package com.jdjt.dams.web;

import java.util.Map;

import com.base.common.utils.JsonMessage;
import com.base.common.utils.map.MapUtil;
import com.base.shiro.web.validator.ResourceValidator;
import com.jdjt.dams.entity.DocIdentityModel;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

public class DocIdentityController extends Controller {

	public void index() {
		// DocumentModel docModel =new DocumentModel();
		// setAttr("docModel", docModel);
		
		render("docIdentityList.jsp");
	}

	public void docIdentityList() {

		// DocumentModel doc=getModel(DocumentModel.class,"docModel");
		// int start=(getParaToInt("start")!=0)?getParaToInt("start"):1;
		int pageNumber = (getParaToInt("pageIndex") != 0) ? getParaToInt("pageIndex") + 1 : 1;
		int pageSize = (getParaToInt("limit") != 0) ? getParaToInt("limit") : 10;
		Page<DocIdentityModel> docList = DocIdentityModel.dao.paginate(pageNumber, pageSize);
		Map<String, Object> map = MapUtil.toModel("rows", docList);
		// map.put("rows",goodsModelList.getList() );
		map.put("results", docList.getTotalRow());
		map.put("hasError", false);
		renderJson(map);
	}
	
	
	
	public void add() {
		render("docCateAdd.jsp");
	}

	public void edit() {
		setAttr("docCate", DocIdentityModel.dao.findById(getParaToInt()));
		render("docCateEdit.jsp");
	}

	public void view() {
		setAttr("docCate", DocIdentityModel.dao.findById(getParaToInt()));
		render("docCateView.jsp");
	}

	@Before(ResourceValidator.class)
	public void save() {
		getModel(DocIdentityModel.class).save();
		redirect("/ms/docCate");
	}

	@Before(ResourceValidator.class)
	public void update() {
		getModel(DocIdentityModel.class).update();
		redirect("/ms/docCate");
	}

	public void delete() {
		DocIdentityModel.dao.deleteById(getParaToInt());
		redirect("/ms/docCate");
	}
	public void deleteBatch() {		
		String ids[]= getParaValues("ids[]");		
		System.out.println(ids);
		boolean bool = false;
		if(ids!=null){
		for(int i=0;i<ids.length;i++){
			bool=DocIdentityModel.dao.deleteById(ids[i]);	
			}		
		}
		renderJson(JsonMessage.message(bool));
	}
	
}
